'''

RadioButtun

QCheckBox

'''


import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

class RadioButtun(QWidget):

    def __init__(self):
        super(RadioButtun, self).__init__()

        self.initUI()
        self.show()

    def initUI(self):

        self.setWindowTitle("Menu")
        layout = QHBoxLayout()

        self.btn0 = QRadioButton('0')
        self.btn0.setChecked(True)
        self.btn0.toggled.connect(self.buttonState)

        self.btn1 = QRadioButton('1')
        self.btn1.toggled.connect(self.buttonState)

        layout.addWidget(self.btn0)
        layout.addWidget(self.btn1)
        self.setLayout(layout)

    def buttonState(self):
        radioB = self.sender()
        if radioB.text() == '0':
            if radioB.isChecked():
                print("0")
            else:
                print('--------')
        if radioB.text() == '1':
            if radioB.isChecked():
                print("1")
            else:
                print('--------')


class QCheckBoxDemo(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()
        self.show()
    def initUI(self):

        self.setWindowTitle("复选框控件演示")
        layout = QHBoxLayout()

        self.checkbox1 = QCheckBox("复选框1")
        self.checkbox1.setChecked(True)
        self.checkbox1.stateChanged.connect(lambda: self.checkedStatus(self.checkbox1))

        self.checkbox2 = QCheckBox("复选框2")
        self.checkbox2.stateChanged.connect(lambda: self.checkedStatus(self.checkbox2))

        self.checkbox3 = QCheckBox("复选框3")
        self.checkbox3.setTristate(True)
        self.checkbox3.setCheckState(Qt.PartiallyChecked)
        self.checkbox3.stateChanged.connect(lambda: self.checkedStatus(self.checkbox2))

        layout.addWidget(self.checkbox1)
        layout.addWidget(self.checkbox2)
        layout.addWidget(self.checkbox3)

        self.setLayout(layout)

    def checkedStatus(self, cb):

        checkbox1status = self.checkbox1.text() + ', isChecked=' + str(self.checkbox1.isChecked())
        checkbox2status = self.checkbox2.text() + ', isChecked=' + str(self.checkbox2.isChecked())
        checkbox3status = self.checkbox3.text() + ', isChecked=' + str(self.checkbox3.isChecked())

        print(checkbox1status+checkbox2status+checkbox3status)

if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = QCheckBoxDemo()

    sys.exit(app.exec_())